package com.youlai.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.system.mapper.SysDegreeMapper;
import com.youlai.system.model.entity.SysDegree;
import com.youlai.system.model.query.DegreePageQuery;
import com.youlai.system.model.vo.DegreePageVO;
import com.youlai.system.service.SysDegreeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class SysDegreeServiceImpl extends ServiceImpl<SysDegreeMapper, SysDegree> implements SysDegreeService {
    @Override
    public SysDegree getStuCourseDegree(Long studentId, Long courseId) {
        LambdaQueryWrapper<SysDegree> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysDegree::getStudentId, studentId).eq(SysDegree::getCourseId, courseId);
        return getOne(queryWrapper);
    }

    @Override
    public IPage<DegreePageVO> getDegreePage(DegreePageQuery queryParams) {
        // 参数构建
        int pageNum = queryParams.getPageNum();
        int pageSize = queryParams.getPageSize();
        Page<DegreePageVO> page = new Page<>(pageNum, pageSize);
        // 查询数据
        Page<DegreePageVO> degreePage = this.baseMapper.getDegreePage(page, queryParams);
        // 实体转换
        return degreePage;
    }

    @Override
    public boolean clearDegreeBy(Long studentId, Long courseId) {
        LambdaQueryWrapper<SysDegree> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysDegree::getStudentId, studentId).eq(SysDegree::getCourseId, courseId);
        return remove(queryWrapper);
    }

    @Override
    public boolean clearDegreeByCourseId(Long courseId) {
        LambdaQueryWrapper<SysDegree> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysDegree::getCourseId, courseId);
        return remove(queryWrapper);
    }
}
